<html>
<head><meta charset="utf-8"><title>Request: warn if target_arch doesn&#x27;t match known arches · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html">Request: warn if target_arch doesn&#x27;t match known arches</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240676134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240676134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240676134">(May 29 2021 at 01:24)</a>:</h4>
<p>What it says on the tin. A warning to make target_arch generate a warning if you're checking for an arch that rustc doesn't know about? This could even be off by default, but i had some code lurking that was cfg'd for <code>x86_86</code> and the only test was a doctest which then also didn't get tested and it all went un-noticed because this crate has 1236 functions in it. I only noticed while converting the doctests into integration tests.</p>



<a name="240676360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240676360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240676360">(May 29 2021 at 01:30)</a>:</h4>
<p>Reminds me of <a href="https://github.com/rust-lang/rfcs/pull/3013">https://github.com/rust-lang/rfcs/pull/3013</a></p>
<p>Oh, <code>target_arch</code> looks like it's even in there: <a href="https://github.com/rust-lang/rfcs/blob/master/text/3013-conditional-compilation-checking.md#well-known-condition-names">https://github.com/rust-lang/rfcs/blob/master/text/3013-conditional-compilation-checking.md#well-known-condition-names</a></p>



<a name="240676474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240676474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240676474">(May 29 2021 at 01:33)</a>:</h4>
<blockquote>
<p>i had some code lurking that was cfg'd for x86_86</p>
</blockquote>
<p>your code was forward thinking, and handling intel's future extension to 86-bit pointers</p>



<a name="240676890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240676890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240676890">(May 29 2021 at 01:40)</a>:</h4>
<blockquote>
<p>One possible source of problems may come from build scripts (<a href="http://build.rs">build.rs</a> files) that add --cfg options that Cargo is not aware of. For exaple, if a Cargo.toml file did not define a feature flag of foo, but the <a href="http://build.rs">build.rs</a> file added a --cfg feature="foo" option, then source code could use foo in a condition. My guess is that this is rare, and that a Crater run will expose this kind of problem.</p>
</blockquote>
<p>I have literally done this lifehack myself.</p>



<a name="240677040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240677040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240677040">(May 29 2021 at 01:44)</a>:</h4>
<p>Anyway, i suppose it's neat that some sort of hyper general version of this is in the works. though, having it all be opt-in seems not great in the long term.</p>



<a name="240677152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240677152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240677152">(May 29 2021 at 01:48)</a>:</h4>
<p>i always name the cfg something specific. even if i'm shimming stuff like <code>cfg(sanitize)</code>, which is trivially shimmable (<a href="https://github.com/rust-lang/rust/issues/39699#issuecomment-814134019">https://github.com/rust-lang/rust/issues/39699#issuecomment-814134019</a>)</p>



<a name="240678906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240678906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240678906">(May 29 2021 at 02:39)</a>:</h4>
<p>There is a proposal to make <a href="http://build.rs">build.rs</a> list all possible cfg values it might set.</p>



<a name="240679289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240679289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240679289">(May 29 2021 at 02:50)</a>:</h4>
<p>If it includes key-value pairs, that could become annoying to exhausitvely enumerate set values. I've used cfg values with feature detection (side note: that is really fun in <a href="http://build.rs">build.rs</a>, much nicer in cmake). For example, the <a href="http://build.rs">build.rs</a> script for lccc's libstd (Current state: &lt;<a href="https://github.com/LightningCreations/lccc/blob/main/rust/libstd/build.rs">https://github.com/LightningCreations/lccc/blob/main/rust/libstd/build.rs</a>&gt;) will likely end up setting more than a dozen different cfg values to well too many different values. Being required to print all possible pairs sounds like it could end up with a right-hand/left-hand problem I'd desparetly like to avoid (Where I add a new pair as I implement more stuff, or refine the checks, but forget to add it to the list).</p>



<a name="240679303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240679303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240679303">(May 29 2021 at 02:51)</a>:</h4>
<p>(There is also a decent chance I'll end up doing something similar in other projects, so it's not just something that could be solved with "add an unstable option to deactivate it")</p>



<a name="240681552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240681552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240681552">(May 29 2021 at 04:06)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> The feature as discussed was exclusively for feature flags; rust cfgs don't have key-value pairs yet.</p>



<a name="240681637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240681637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240681637">(May 29 2021 at 04:08)</a>:</h4>
<p>Can't you set <code>key="value"</code> in <a href="http://build.rs">build.rs</a> with <code>cargo:rustc-cfg=</code>?</p>



<a name="240681646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240681646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240681646">(May 29 2021 at 04:09)</a>:</h4>
<p>yeah, you can</p>



<a name="240681651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240681651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240681651">(May 29 2021 at 04:09)</a>:</h4>
<p>(Which is what I mean by key-value pairs)</p>



<a name="240681715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240681715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240681715">(May 29 2021 at 04:11)</a>:</h4>
<p>This is true, but you can't actually do anything with the "value", so it still just amounts to a key with a complex name.</p>



<a name="240681728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240681728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240681728">(May 29 2021 at 04:11)</a>:</h4>
<p>It acts effectively like a key named <code>key=value</code>; you can't actually do anything with the value except check it against a literal string.</p>



<a name="240681827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240681827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240681827">(May 29 2021 at 04:14)</a>:</h4>
<p>Well, that's specifically what I need anyways.  If I had to exhausitvely list all of those keys, that could become a <em>fun</em>  problem.</p>



<a name="240688454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Request%3A%20warn%20if%20target_arch%20doesn%27t%20match%20known%20arches/near/240688454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Request.3A.20warn.20if.20target_arch.20doesn&#x27;t.20match.20known.20arches.html#240688454">(May 29 2021 at 07:07)</a>:</h4>
<blockquote>
<p>There is a proposal to make <a href="http://build.rs">build.rs</a> list all possible cfg values it might set.</p>
</blockquote>
<p>target_arch isn't set in <a href="http://build.rs">build.rs</a> though, it's just set by the compiler itself.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>